{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "490d30bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0559a3a3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c7954d53",
   "metadata": {},
   "outputs": [],
   "source": [
    "files = list(filter(lambda item: item.startswith(\"SafeFlowsQueryTest\"), os.listdir(\"./\")))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6b843dfe",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['SafeFlowsQueryTest__20200701_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200702_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200703_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200704_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200705_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200706_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200707_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200708_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200709_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200710_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200711_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200712_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200713_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200714_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200715_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200716_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200717_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200718_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200719_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200720_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200721_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200722_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200723_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200724_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200725_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200726_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200727_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200728_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200729_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200730_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200731_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200801_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200802_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200803_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200804_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200805_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200806_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200807_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200808_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200809_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200810_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200811_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200812_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200813_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200814_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200815_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200816_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200817_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200818_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200819_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200820_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200821_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200822_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200823_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200824_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200825_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200826_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200827_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200828_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200829_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200830_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200831_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200901_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200902_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200903_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200904_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200905_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200906_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200907_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200908_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200909_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200910_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200911_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200912_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200913_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200914_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200915_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200916_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200917_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200918_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200919_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200920_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200921_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200922_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200923_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200924_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200925_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200926_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200927_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200928_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200929_flows.csv',\n",
       " 'SafeFlowsQueryTest__20200930_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201001_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201002_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201003_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201004_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201005_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201006_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201007_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201008_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201009_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201010_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201011_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201012_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201013_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201014_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201015_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201016_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201017_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201018_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201019_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201020_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201021_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201022_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201023_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201024_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201025_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201026_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201027_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201028_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201029_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201030_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201031_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201101_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201102_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201103_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201104_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201105_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201106_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201107_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201108_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201109_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201110_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201111_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201112_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201113_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201114_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201115_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201116_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201117_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201118_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201119_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201120_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201121_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201122_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201123_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201124_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201125_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201126_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201127_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201128_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201129_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201130_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201201_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201202_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201203_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201204_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201205_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201206_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201207_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201208_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201209_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201210_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201211_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201212_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201213_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201214_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201215_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201216_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201217_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201218_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201219_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201220_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201221_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201222_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201223_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201224_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201225_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201226_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201227_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201228_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201229_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201230_flows.csv',\n",
       " 'SafeFlowsQueryTest__20201231_flows.csv']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d7bd0f4c",
   "metadata": {},
   "outputs": [],
   "source": [
    "frames = []\n",
    "for file in files:\n",
    "    data = pd.read_csv(file, encoding=\"UTF-8\")\n",
    "    columns = data.columns\n",
    "    data = data.rename(columns={columns[0]: columns[0].split(\".\")[1], columns[1]: columns[1].split(\".\")[1], columns[2]: columns[2].split(\".\")[1]})\n",
    "    frames.append(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "80172db0",
   "metadata": {},
   "outputs": [],
   "source": [
    "result = pd.concat(frames)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "d13e6859",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>trade_money</th>\n",
       "      <th>c_time</th>\n",
       "      <th>member_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10.00</td>\n",
       "      <td>1593562639</td>\n",
       "      <td>2071139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>40.00</td>\n",
       "      <td>1593570814</td>\n",
       "      <td>3437336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6.00</td>\n",
       "      <td>1593570977</td>\n",
       "      <td>3124580</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.00</td>\n",
       "      <td>1593578525</td>\n",
       "      <td>3437336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>34.00</td>\n",
       "      <td>1593581034</td>\n",
       "      <td>3272271</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2073</th>\n",
       "      <td>6.00</td>\n",
       "      <td>1609418687</td>\n",
       "      <td>3247753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2074</th>\n",
       "      <td>15.00</td>\n",
       "      <td>1609421932</td>\n",
       "      <td>1630546</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2075</th>\n",
       "      <td>14.00</td>\n",
       "      <td>1609426596</td>\n",
       "      <td>3234030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2076</th>\n",
       "      <td>0.02</td>\n",
       "      <td>1609428031</td>\n",
       "      <td>2220341</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2077</th>\n",
       "      <td>0.02</td>\n",
       "      <td>1609428579</td>\n",
       "      <td>2227209</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>89666 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      trade_money      c_time  member_id\n",
       "0           10.00  1593562639    2071139\n",
       "1           40.00  1593570814    3437336\n",
       "2            6.00  1593570977    3124580\n",
       "3            4.00  1593578525    3437336\n",
       "4           34.00  1593581034    3272271\n",
       "...           ...         ...        ...\n",
       "2073         6.00  1609418687    3247753\n",
       "2074        15.00  1609421932    1630546\n",
       "2075        14.00  1609426596    3234030\n",
       "2076         0.02  1609428031    2220341\n",
       "2077         0.02  1609428579    2227209\n",
       "\n",
       "[89666 rows x 3 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a3efc5dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "cleaned = result[result[\"trade_money\"] >= 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "303c66ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "bundle = cleaned.groupby([\"member_id\", \"c_time\"]).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "beab8d67",
   "metadata": {},
   "outputs": [],
   "source": [
    "allMembers = cleaned[\"member_id\"].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "ead15379",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"结果文件.csv\", 'w') as file:\n",
    "    file.write(\"member_id,第一笔金额,第一笔时间,第二笔金额,第二笔时间\")\n",
    "    for member in allMembers:\n",
    "        indexes = bundle[\"trade_money\"][member].index.astype(str).to_list()\n",
    "        values = bundle[\"trade_money\"][member].to_list()\n",
    "        # \n",
    "        file.write(f\"{member},{values[0]},{indexes[0]}\")\n",
    "        if len(indexes) > 1:\n",
    "            file.write(f\",{values[1]},{indexes[1]}\")\n",
    "        file.write(\"\\r\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "7c4e4db7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba7f48df",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
